from multiprocessing import Pool, Process, Queue
import time, os


def work(x):
    print(f'I am start{str(x)}!')
    time.sleep(1)
    print(f'I am end{str(x)}!')


if __name__ == '__main__':
    print(os.getpid())
    p = Pool()
    for i in range(5):
        p.apply_async(work, args=(i,))
    p.close()
    p.join()
    print('I am process Pool')


# 进程通信： Queue

def write_queue(q):
    list_name = ['张三', '李四', '王五', '赵六']
    for i in list_name:
        q.put(i)
        time.sleep(1)
    print('进站成功!')


def read_queuq(q):
    print('开始下车!')
    while 1:
        name = q.get()
        print('%s下车成功!'%name)


if __name__ == '__main__':
    q = Queue()
    pw = Process(target=write_queue, args=(q,))
    pr = Process(target=read_queuq, args=(q,))
    pw.start()
    pr.start()
    pw.join()
    pr.terminate()

